<?
	include_once ("../include/conn.php");
	include_once ('config.php');

	/**************************************** *********************
	****************获取用户信息,高级问卷次数 个人中心页面*****************
	************************************************************/

	//开始数据处理
	$openid = $_GET['openid'];
	$unionid = $_GET['unionid'];

	$results = array('code' => 0,'msg'=>'数据正常！');//用于正常有数据输出的

	//////////////////////////// 取出用户信息 //////////////////////////
	// 如果没用unionid就用openid
	/*
	if($unionid){
		$cmd = "select u.*,COALESCE(q.count,0) qn_count from {$TABLE_C}user u left join(select count(*) count,unionid from {$TABLE_C}vote_qn group by unionid) q on q.unionid=u.unionid where u.unionid='$unionid'";
	}else{
		$cmd = "select u.*,COALESCE(q.count,0) qn_count from {$TABLE_C}user u left join(select count(*) count,unionid from {$TABLE_C}vote_qn group by unionid) q on q.unionid=u.unionid where u.openid='$openid'";
	}*/

	$cmd = "
		select u.* 
		,COALESCE(q.count,0) qn_count 
		,c.title company_name 
		,s.name scope_name 
		from {$TABLE_C}user u 
		left join(select count(*) count,unionid from {$TABLE_C}vote_qn group by unionid) q on q.unionid=u.unionid 
		left join(select * from {$TABLE_C}company) c on c.id = u.company 
		left join(select * from {$TABLE_C}vote_scope) s on s.id = c.scope_id
		where u.unionid='$unionid'
	";
	
	// 执行
	$row = $mydb->fetch_assoc($cmd);
	//输出数据
	$results['userInfo'] = $row;
	
	// //////////////////输出数据////////////////////////////////
	echo decodeUnicode(json_encode($results));
	// 结束
	mysql_close();
?>